﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLiNhaSachBUS;

namespace QuanLiNhaSachGUI
{
    public partial class frmTimKiem : Form
    {
        public frmTimKiem()
        {
            InitializeComponent();
        }

        private void txtNoiDung_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void frmTimKiem_Load(object sender, EventArgs e)
        {
            cbTheo.SelectedIndex = 0;
        }

        private void cbTheo_SelectedIndexChanged(object sender, EventArgs e)
        {
            string theo = "";
            switch (cbTheo.SelectedIndex + 1)
            {
                case 1:
                    theo = "Sach";
                    break;
                case 2:
                    theo = "NhanVien";
                    break;
                case 3:
                    theo = "TheLoai";
                    break;
                case 4:
                    theo = "NhaXuatBan";
                    break;
                case 5:
                    theo = "NhaCungCap";
                    break;
                default:
                    theo = "TacGia";
                    break;
            }
            dataGridView1.DataSource = null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string theo = "";
            switch (cbTheo.SelectedIndex + 1)
            {
                case 1:
                    theo = "Sach";
                    break;
                case 2:
                    theo = "NhanVien";
                    break;
                case 3:
                    theo = "TheLoai";
                    break;
                case 4:
                    theo = "NhaXuatBan";
                    break;
                case 5:
                    theo = "NhaCungCap";
                    break;
                default:
                    theo = "TacGia";
                    break;
            }
            dataGridView1.DataSource = TimKiemBUS.Tim(theo, txtNoiDung.Text);
            dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }

        private void frmTimKiem_FormClosed(object sender, FormClosedEventArgs e)
        {
            frmMain.listForm.Remove(this);
        }
    }
}
